package hdd.config;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
import service.TestService;


@Configuration
@PropertySource({"classpath:setting.properties"})
public class RmiBeanConfig implements EnvironmentAware {
    private Environment environment;
    @Bean
    public RmiProxyFactoryBean rmiProxyFactoryBean(){
        RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
        StringBuffer serviceUrl = new StringBuffer("rmi://");
        serviceUrl.append(environment.getProperty("rmi.registryHost")).append(":");
        serviceUrl.append(environment.getProperty("rmi.servicePort")).append("/").append(TestService.class.getSimpleName());
        rmiProxyFactoryBean.setServiceUrl(serviceUrl.toString());
        rmiProxyFactoryBean.setServiceInterface(TestService.class);
        rmiProxyFactoryBean.setLookupStubOnStartup( false );
        return rmiProxyFactoryBean;
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
